home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / SRC / HOARDDLL.ZIP / 3rdParty / hoard / libhoard-2.0.2 / arch-specific.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-06-18  |  4.1 KB  |  176 lines

  1. ///-*-C++-*-//////////////////////////////////////////////////////////////////
  2. //
  3. // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
  4. //        for Shared-Memory Multiprocessors
  5. // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
  6. //
  7. // Copyright (c) 1998-2000, The University of Texas at Austin.
  8. //
  9. // This library is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU Library General Public License as
  11. // published by the Free Software Foundation, http://www.fsf.org.
  12. //
  13. // This library is distributed in the hope that it will be useful, but
  14. // WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. //////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Note: This file was modified by Crystal Decisions in June 2002.
  24. //
  25. //////////////////////////////////////////////////////////////////////////////
  26.  
  27.  
  28. #ifndef _ARCH_SPECIFIC_H_
  29. #define _ARCH_SPECIFIC_H_
  30.  
  31. #include "config.h"
  32.  
  33. #if defined(CRYSTAL_HOARD)
  34. // The values of a user-level lock.
  35. enum { UNLOCKED = 0, LOCKED = 1 };
  36. #endif
  37.  
  38. // Wrap architecture-specific functions.
  39.  
  40. #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
  41.  
  42. // Windows
  43.  
  44. #ifndef WIN32
  45. #define WIN32 1
  46. #endif
  47. #include <windows.h>
  48. #include <process.h>
  49. typedef LONG    hoardLockType;
  50. typedef CRITICAL_SECTION  hoardLockTypeS;
  51.  
  52. typedef HANDLE     hoardThreadType;
  53.  
  54. #elif defined(__BEOS__)
  55.  
  56. // BeOS
  57.  
  58. #include <OS.h>
  59.  
  60.  
  61. #elif USE_SPROC
  62.  
  63. // SGI's SPROC library
  64.  
  65. #include <sys/types.h>
  66. #include <sys/prctl.h>
  67.  
  68. #else
  69.  
  70. // Generic UNIX
  71.  
  72. #if defined(__SVR4) // Solaris
  73. #include <thread.h>
  74. #endif
  75.  
  76. #include <pthread.h>
  77. #include <unistd.h>
  78.  
  79. #endif
  80.  
  81.  
  82. #ifndef WIN32
  83. #if defined(__BEOS__)
  84. typedef struct {
  85.   int32 ben;
  86.   sem_id sem;
  87. } hoardLockType;
  88. #elif USER_LOCKS && (defined(i386) || defined(sparc) || defined(__sgi))
  89. typedef unsigned long    hoardLockType;
  90. #else
  91. typedef pthread_mutex_t    hoardLockType;
  92. #endif
  93.  
  94. #if USE_SPROC
  95. typedef pid_t            hoardThreadType;
  96. #elif defined(__BEOS__)
  97. typedef thread_id               hoardThreadType;
  98. #else
  99. typedef pthread_t        hoardThreadType;
  100. #endif
  101.  
  102. #endif
  103.  
  104. #if !defined(WIN32)
  105. extern "C" {
  106. #endif  
  107.  
  108.   ///// Thread-related wrappers.
  109.  
  110.   void    hoardCreateThread (hoardThreadType& t,
  111.                void *(*function) (void *),
  112.                void * arg);
  113.   void    hoardJoinThread (hoardThreadType& t);
  114.   void  hoardSetConcurrency (int n);
  115.  
  116.   // Return a thread identifier appropriate for hashing:
  117.   // if the system doesn't produce consecutive thread id's,
  118.   // some hackery may be necessary.
  119.   int    hoardGetThreadID (void);
  120.  
  121.   ///// Lock-related wrappers.
  122.  
  123. #if !defined(WIN32) && !defined(__BEOS__) && !USER_LOCKS
  124.  
  125.   // Define the lock operations inline to save a little overhead.
  126.  
  127.   inline void hoardLockInit (hoardLockType& lock) {
  128.     pthread_mutex_init (&lock, NULL);
  129.   }
  130.  
  131.   inline void hoardLock (hoardLockType& lock) {
  132.     pthread_mutex_lock (&lock);
  133.   }
  134.  
  135.   inline void hoardUnlock (hoardLockType& lock) {
  136.     pthread_mutex_unlock (&lock);
  137.   }
  138. #else
  139.   void    hoardLockInit (hoardLockType& lock);
  140.   void    hoardLock (hoardLockType& lock);
  141.   void    hoardUnlock (hoardLockType& lock);
  142.   
  143. #endif
  144.  
  145. #if defined(WIN32)
  146.   void    hoardLockInit (hoardLockTypeS& lock);
  147.   void    hoardLock (hoardLockTypeS& lock);
  148.   void    hoardUnlock (hoardLockTypeS& lock);
  149. #endif
  150.  
  151.   ///// Memory-related wrapper.
  152.  
  153.   int    hoardGetPageSize (void);
  154.   void *    hoardSbrk (long size);
  155.   void    hoardUnsbrk (void * ptr, long size);
  156.  
  157.   ///// Other.
  158.  
  159.   void  hoardYield (void);
  160.   int    hoardGetNumProcessors (void);
  161.   unsigned long hoardInterlockedExchange (unsigned long * oldval,
  162.                       unsigned long newval);
  163.  
  164.   // The Crystal Decisions Win32 version of the Hoard can identify
  165.   // pointers that belong to itself.
  166. #if defined(WIN32) && defined(CRYSTAL_HOARD)
  167.   bool hoardIsHoardPtr(void * ptr);
  168. #endif
  169.  
  170. #if !defined(WIN32)
  171. }       // extern "C"
  172. #endif  
  173.  
  174. #endif // _ARCH_SPECIFIC_H_
  175.  
  176.